<?php
//Start session
	session_start();

	//Array to store validation errors
	$errmsg_arr = array();

	//Validation error flag
	$errflag = false;

	//Sanitize the POST values
	$enquiries = $_POST['enquiries'];
	$service = $_POST['service'];
	$fname = $_POST['fname'];
	$email = $_POST['email'];
	$phone = $_POST['phone'];
	$address = $_POST['address'];
	$address2 = $_POST['address2'];
	$furtherInfo = $_POST['further-info'];


	if($address2 != ""){
		$add = $address.', '.$address2;
	}else{
		$add = $address;
	}
	if($furtherInfo != ""){
		$msg = $furtherInfo;
	}else{
		$msg = "No additional information supplied.";
	}
	if($enquiries == '') {
		$errmsg_arr[] = 'Please select your enquiry';
		$errflag = true;
	}
	if($service == '') {
		$errmsg_arr[] = 'Please select the service your enquiry is about';
		$errflag = true;
	}
	if($fname == '') {
		$errmsg_arr[] = 'First name is required';
		$errflag = true;
	}
	if($phone == '') {
		$errmsg_arr[] = 'Phone number is required';
		$errflag = true;
	}
	if($email == '') {
		$errmsg_arr[] = 'Email is required';
		$errflag = true;
	}

$page = $_SERVER['HTTP_REFERER'];
if($errflag) {
		$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
		session_write_close();
		header("location: $page");
		exit();
	}
	else{
	$_SESSION['Thanks']="Thank you for your message, we'll get back to you as soon as possible.";
$sendto = "info@divinecleaningservices.co.nz";
$subject = "Website Enquiries from $fname";
$message = "Hello\n\n An enquiry has been submitted with the following details:\n\nFull name: $fname $lname\n Phone number: $phone\n Email: $email\n Address: $add\n\n Enquiry type: $enquiries\n Service: $service\n Additional Information: $msg\n\n This is an automatic email, please do not reply.\n--------------------------- END ---------------------------";
$header = "From: auto-notice@divinecleaningservices.co.nz\r\n";
mail($sendto, $subject, $message, $header);
		$_SESSION['thanks'] = "Thanks for your message, we'll get back to you as soon as possible.";
 		header("location: ../");
		exit();
}//end errflag


?>